<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script src="./Promise.js"></script>
  <script>
    const p = new Promise((resolve, reject) => {
      // resolve(1)

      // reject(2)

      setTimeout(() => {
        // resolve(3)
        reject(4)
      }, 1000);
    })
    p.then(
      value => {
        console.log('onResovled1', value)
      },
      reason => {
        console.log('onRejected1', reason)
        // 返回promise
        // return new Promise((resolve, reject) => {
        //   // resolve(2)
        //   // reject(3)
        // })

        // 返回非Promse
        // return 4

        // 抛出错误
        throw 5

      }
    ).then(
      // value => {
      //   console.log('onResovled2', value)
      // },
      // reason => {
      //   console.log('onRejected2', reason)
      // }
    )
    .then(
      value => {
        console.log('onResovled3', value)
      },
      reason => {
        console.log('onRejected3', reason)
        throw 6
        // return 6
      }
    )
    .catch(
      reason => {
        console.log('onRejected4', reason)
      }
    )
    .then(
      value => {
        console.log('onResovled5', value)
      },
      reason => {
        console.log('onRejected5', reason)
      }
    )
    /* 
    对象快照: 输出当时, 对象的样子(对象的数据) => 显示在外层是快照
    后面对象内部的数据可能会发生变化  ==> 打开显示的此时对象的数据
    */
    // var obj = {m: 1}
    // console.log(obj) // {m: 1}
    // setTimeout(() => {
    //   obj.m = 2   // {m: 2}
    // }, 1000);
  </script>
</body>
</html>